package com.alone.openai.api.core.param;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.List;

/**
 * @author Alone
 * @date 2023/3/22 10:37 上午
 */
@Data
public class ChatResponse {
    private String id;
    private String object;
    private int created;
    private String model;
    private Usage usage;
    private List<ChatChoice> choices;

    public String getContent() {
        if (CollUtil.isEmpty(choices)) {
            return "";
        }
        return choices.get(0).getMessage().getContent();
    }

    public String getHtmlContent() {
        String content = getContent();
        if (StrUtil.isNotBlank(content)) {
            content = content.replaceFirst("\n", "")
                    .replaceFirst("\n", "")
                    .replace("\n", "<br/>");
        }
        return content;
    }

}
